home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 August: Tool Chest / Apple_Developer_Group_August_1996_Tool_Chest.iso / Sample Code / Toolbox / RAMDisk 1.2 / Sources / Driver.a next >
Encoding:
Text File  |  1995-07-19  |  4.1 KB  |  140 lines  |  [TEXT/MPS ]

  1. **
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Driver.a: MPW DRVR header and glue for RamDisk
  5. **
  6. **    by Gordon Sheridan and Jim Luther
  7. **  modified by Brian Bechtel
  8. **
  9. **    File:        RamCDev.c
  10. **
  11. **    Copyright © 1992-1994 Apple Computer, Inc.
  12. **    All rights reserved.
  13. **
  14. **    You may incorporate this sample code into your applications without
  15. **    restriction, though the sample code has been provided "AS IS" and the
  16. **    responsibility for its operation is 100% yours.  However, what you are
  17. **    not permitted to do is to redistribute the source as "DTS Sample Code"
  18. **    after having made changes. If you're going to re-distribute the source,
  19. **    we require that you make it clear in the source that the code was
  20. **    descended from Apple Sample Code, but that you've made changes.
  21. **
  22. **    Change History (most recent first):
  23. **
  24. **    Change History (most recent first):
  25. **
  26. **         <1>     10/94    BL°B        Corrected asynch not-complete return case
  27. **                                    to put 0 in D0.
  28. **         <0>     10/93    gs and JML    Clean up for Sample Code release.
  29. **
  30.  
  31.         STRING    PASCAL
  32.         CASE    ON
  33.  
  34.         MAIN
  35.  
  36.         IMPORT DRVROPEN
  37.         IMPORT DRVRPRIME
  38.         IMPORT DRVRCONTROL
  39.         IMPORT DRVRSTATUS
  40.         IMPORT DRVRCLOSE
  41.  
  42.         INCLUDE 'SysEqu.a'
  43.  
  44.  
  45. DHeader
  46.  
  47. DFlags            DC.B    0                                    ; set by DRVROpen
  48.                 DC.B    0                                    ; set by DRVROpen
  49. DDelay            DC.W    0                                    ; none
  50. DEMask            DC.W    0                                    ; da event mask
  51. DMenu            DC.W    0                                    ; no menu
  52.  
  53.                 DC.W    DOpen     - DHeader                    ; offset to Open
  54.                 DC.W    DPrime     - DHeader                    ; offset to Prime
  55.                 DC.W    DControl - DHeader                    ; offset to Control
  56.                 DC.W    DStatus     - DHeader                    ; offset to Status
  57.                 DC.W    DClose     - DHeader                    ; offset to Close
  58.  
  59. Name            DC.B    '.RamDRVR'                            ; name of driver
  60.                 ALIGN    2                                    ; word align
  61.  
  62. DOpen            pea        DRVROPEN
  63.                 bra.s    DRVRDispatch
  64.                 
  65. DPrime            pea        DRVRPRIME
  66.                 bra.s    DRVRDispatch
  67.                 
  68. DControl        pea        DRVRCONTROL
  69.                 bra.s    DRVRDispatch
  70.  
  71. DStatus            pea        DRVRSTATUS
  72.                 bra.s    DRVRDispatch
  73.  
  74. DClose            pea        DRVRCLOSE                ; and fall thru to DRVRDispatch
  75.  
  76. DRVRDispatch
  77.                 movem.l    a0/a1, -(sp)            ; save registers (for IODone)
  78.                 
  79. ; call driver routines with Pascal calling conventions
  80.                 clr.w    -(sp)                    ; save room for result
  81.                 move.l    a0, -(sp)                ; push paramblock ptr on stack
  82.                 move.l    a1, -(sp)                ; push dce ptr on stack
  83.                 movea.l $12(sp), a0                ; load address of driver routine into a0
  84.                 jsr        (a0)                    ; go to it!
  85.                 
  86.                 move.w    (sp)+, d0                ; put result into d0                
  87.                 movem.l    (sp)+, a0/a1            ; restore registers (for IODone)
  88.                 addq.w    #4, a7                    ; clear driver routine address off stack
  89.  
  90. ; Check for special case exits (Open, Close, KillIO, Immediate, incomplete Async)
  91. ; Open, Close and KillIO always RTS to the Device Manager with the driver result
  92. ; in 
  93.  
  94.                 move.w    ioTrap(a0), d1            ; copy low byte of trap word to d1
  95.  
  96.     ; _Open check
  97.                 tst.b    d1                        ; _Open == A000
  98.                 beq.s    Done                    ; rts if _Open
  99.  
  100.     ; _Close check
  101.                 cmpi.b    #1, d1                    ; _Close == A001
  102.                 beq.s    Done                    ; rts if _Close
  103.  
  104.     ; _KillIO check
  105.                 cmpi.b    #6, d1                    ; _KillIO == A006
  106.                 beq.s    Done                    ; rts if _KillIO
  107.  
  108.     ; It must be _Read, _Write, _Control, or _Status
  109.     
  110.     ; Immediate check
  111.                 btst    #noQueueBit, d1            ; test immediate bit
  112.                 beq.s    NotImmediate            ; branch if not immediate
  113.                 move.w    d0, ioResult(a0)        ; The Device Manager doesn't set ioResult,
  114.                                                 ; so we do just in case the caller checks
  115.                                                 ; ioResult instead of the function result.
  116.                 bra.s    Done                    ; rts if immediate
  117.                 
  118. NotImmediate
  119.  
  120. ; 941027 BL°B
  121. ; If the call is asynchronous and not complete, it should return noErr (0)
  122. ; in D0 instead of 1 -- otherwise, the Device Manager sees the 1 and
  123. ; returns 1 as an error to the caller. If the File Manager is the caller,
  124. ; it converts the 1 to ioErr and returns it to the program that called
  125. ; it.  See develop issue 13 page 10.
  126. ;
  127.     ; Incomplete Async check
  128.                 cmp.w    #1, d0                    ; We're using the convention that if the
  129.                                                 ; driver result = 1 then the device driver
  130.                                                 ; hasn't completed the non-immediate
  131.                                                 ; operation.
  132.                 bne.s    Complete
  133.                 moveq    #0, d0                    ; clear D0 and...
  134.                 bra.s    Done                    ; rts if the operation is incomplete
  135.  
  136. Complete        move.l    JIODone, -(sp)            ; push jIODone onto stack
  137. Done            rts
  138.  
  139.                 END
  140.